<?php

namespace App\Http\Service\Impl;

use App\Http\Service\IGoods;
use App\Http\Service\IIndex;
use App\Http\Service\IMembers;
use app\Request;
use Illuminate\Support\Facades\DB;
use phpDocumentor\Reflection\Types\Array_;
use Ramsey\Uuid\Uuid;

use function foo\func;

class MembersImpl implements IMembers
{
    /**
     * 用户列表
     * @param $request
     */
    function memberslist($request)
    {
        // TODO: Implement userlist() method.
        return DB::select("SELECT r.phone,r.pwd,m.id,m.username,m.money,m.gold,m.account,
                            case m.isvip
                            when 1 then '是'
                            when 2 then '否'
                            end isvip,
                            case m.status
                            when 1 then '正常'
                            when 2 then '禁用'
                            end status,
                            FROM_UNIXTIME( m.regtime, '%Y-%m-%d' ) regtime ,
                            FROM_UNIXTIME( m.vipstart, '%Y-%m-%d' ) vipstart ,
                            FROM_UNIXTIME( m.vipend, '%Y-%m-%d' ) vipend
                            FROM
                            zhyl_sys_members m
                            left join zhyl_sys_register r on m.rid = r.id
                            limit ?,?",[$request->rows * ($request->page - 1), $request->rows]);
    }

    /**
     * 删除用户
     * @param $request
     */
    function removeuser($request)
    {
        // TODO: Implement removeuser() method.
    }

    function getuserinfo($request)
    {
        // TODO: Implement getuserinfo() method.
        return DB::select("SELECT r.phone,m.username,m.money,m.account,m.status,m.gold,m.isvip,m.id,
                           FROM_UNIXTIME(m.regtime,'%Y-%m-%d') regtime,
                           FROM_UNIXTIME(m.vipstart,'%Y-%m-%d') vipstart,
                           FROM_UNIXTIME(m.vipend,'%Y-%m-%d') vipend
                           FROM
                           zhyl_sys_members m 
                           left join zhyl_sys_register r on m.rid=r.id
                           WHERE
                           m.id = ?",[$request->id]);
    }

    function updateuserinfo($request)
    {

        // TODO: Implement updateuserinfo() method.
        $ups = array(
            "gold"     => $request->gold,
            "isvip"    => $request->isvip,
            "money"    => $request->money,
            "status"   => $request->status,
            "vipend"   => strtotime($request->vipend),
            "vipstart" => strtotime($request->vipstart),
        );
        return DB::table("members")->where("id",$request->id)->update($ups);
    }


}
